package com.fh.bean;


import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import nonapi.io.github.classgraph.json.Id;

import java.util.Calendar;
import java.util.Date;


@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value ="user")
public class User {
    @Id
    private Long id;
    private String username;
    private String password;
    private String role;

    @TableField("accountLocked")
    private Integer accountLocked;

    @TableField("accountExpired")
    private Integer accountExpired;

    @TableField(exist = false)
    private Date credentialsExpirationDate; // 用于存储用户权限的有效时间





    public boolean isAccount(Integer account) {
        return account == 0;
    }

    // 设置凭证过期时间为当前时间加上两个小时
    public void isCredentialsExpired(int amoutTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.HOUR_OF_DAY, amoutTime);
        this.credentialsExpirationDate = calendar.getTime();
    }

    public boolean isCredentialsExpired() {
        if (credentialsExpirationDate == null) {
            return false;
        }
        return credentialsExpirationDate.before(new Date());
    }
}